<template>
  <div id="experimentData">
    <el-card class="box-card" style="margin:15px">
      <div style="margin-bottom:10px">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-folder-checked"
          @click="clickAudit"
        >数据上报</el-button>
        <el-button size="small" type="primary" @click="clickShenhe">提交审核</el-button>
        <el-button size="small" @click="clickDelete">删除</el-button>
        <el-button size="small" @click="getList(basicData)">刷新</el-button>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        style="width: 100%;padding:5px;"
        :header-cell-style="{
          background: '#333333',
          color: '#ffffff',
          textAlign: 'center'
        }"
        @selection-change="selectChanage"
        @row-dblclick="clickDbRow"
      >
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column align="center" prop="batchNumber" label="批号" />
        <el-table-column align="center" prop="experimentCode.data" label="实验项目" />
        <el-table-column align="center" prop="qualityControl.data" label="质控批号" />
        <el-table-column align="center" prop="reagent1.data" label="试剂1" />
        <el-table-column align="center" prop="reagent2.data" label="试剂2" />
        <el-table-column align="center" prop="swatchTime" label="布板日期" width="100">
          <template slot-scope="scope">
            <span>
              {{
              scope.row.swatchTime ? scope.row.swatchTime.substr(0, 10) : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="swatchMan" label="实验人员" />
        <el-table-column align="center" prop="sampleCount" label="样本数" />
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              style="background:#2669F3"
              @click="clickDbRow(scope.row)"
            >布板</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="basicData.current"
        :page-size="basicData.size"
        :total="total"
        layout="slot, total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
        <span
          v-if="tableData.length > 0"
          style="font-weight: 400;color:#606266"
        >已选中{{ tableData.length }}条，</span>
      </el-pagination>
    </el-card>

    <!-- 审核 -->
    <el-dialog
      width="40%"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="审核"
      :visible.sync="auditShow"
      append-to-body
    >
      <el-form
        ref="projectManageForm"
        :model="basicData.model"
        label-width="120px"
        size="small"
        style="display:flex;justify-content: center;"
      >
        <el-form-item label="实验项目:">
          <el-select
            size="mini"
            v-model="basicData.model.experimentCode.key"
            placeholder="选择"
            @change="selectExperimentCode"
          >
            <el-option
              v-for="(item, key, index) in dicts.EXPERIMENT_CODE"
              :key="index"
              :label="item"
              :value="{
                data:item,
                key:key
              }"
            />
          </el-select>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 审核列表 -->
    <el-dialog
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="ExpListShow"
      append-to-body
      fullscreen
    >
      <el-form :model="expListData" label-width="120px" size="small">
        <el-row>
          <el-col :span="4">
            <el-form-item>
              <el-date-picker
                size="mini"
                v-model="expListData.experimentDate"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="日期选择"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="开始序号:">
              <el-input size="mini" v-model="expListData.seq" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="填充实验编号:">
              <div style="display:flex">
                <el-input size="mini" v-model="expListData.startExpNum" placeholder="输入" />
                <span style="margin:0 10px">至</span>
                <el-input size="mini" v-model="expListData.endExpNum" placeholder="输入" />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="display: flex;justify-content: flex-end;padding-right:10%">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-folder-checked"
              @click="clickExpQuery"
            >查询</el-button>
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-folder-checked"
              @click="clickUpdateData"
            >上报</el-button>
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-folder-checked"
              @click="clickSync"
              :disabled="butsab"
            >同步</el-button>
          </el-col>
        </el-row>
        <!-- 中间 -->
        <div>
          <el-row>
            <el-col :span="6">
              <el-form-item>入库数：{{expItem.count}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>α-THA阴性数：{{expItem.alphaTHACount}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>β-THA阴性数：{{expItem.betaTHACount}}</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>M-Hb阴性数：{{expItem.mHbCount}}</el-form-item>
            </el-col>
            <!-- <el-col :span="6">
              <el-form-item>α-THA中位数：19.75</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>α-THA均值：19.75</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>Hb-F中位数：19.75</el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item>Hb-F均值：19.75</el-form-item>
            </el-col>-->
          </el-row>
          <el-table
            v-loading="expLoading"
            :data="expList"
            style="width: 100%;padding:5px;"
            :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
          >
            <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
            <el-table-column align="center" prop="alpha-THA" label="α-THA" />
            <el-table-column align="center" prop="beta-THA" label="β-THA" />
            <el-table-column align="center" prop="M-Hb" label="M-Hb" />
            <el-table-column align="center" prop="dataAnalisi" label="实验日期">
              <template slot-scope="scope">
                <span>
                  {{
                  scope.row.dataAnalisi ? scope.row.dataAnalisi.substr(0, 10) : ""
                  }}
                </span>
              </template>
            </el-table-column>
            <el-table-column align="center" prop="seq" width="55" label="序号" />
            <el-table-column align="center" prop="nomeFirst" label="nome_picco_1" />
            <el-table-column align="center" prop="valPiccoFirst" label="val_picco_1" />
            <el-table-column align="center" prop="nomeSecond" label="nome_picco_2" />
            <el-table-column align="center" prop="valPiccoSecond" label="val_picco_2" />
            <el-table-column align="center" prop="nomeThird" label="nome_picco_3" />
            <el-table-column align="center" prop="valPiccoThird" label="val_picco_3" />
          </el-table>
        </div>
      </el-form>
    </el-dialog>

    <!-- 布板 -->
    <el-dialog
      width="85%"
      append-to-body
      id="experimentData-dialog"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="布板"
      :visible.sync="bubanShow"
    >
      <el-form
        ref="basicForm"
        :rules="bubanAddFormRules"
        :inline="true"
        :model="bubanAddForm"
        class="demo-form-inline"
        size="small"
        label-width="100px"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="实验批号:" prop="batchNumber">
              <el-input size="mini" v-model="bubanAddForm.batchNumber" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板方案:" prop="swatchId.key">
              <el-select
                size="mini"
                v-model="bubanAddForm.swatchId.key"
                placeholder="选择"
                @change="swatchIdChanage"
              >
                <el-option
                  v-for="(item, index) in swatchList"
                  :key="index"
                  :label="item.swatchName"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板人员:" prop="swatchMan">
              <el-input size="mini" v-model="bubanAddForm.swatchMan" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="布板日期:" prop="swatchTime">
              <el-date-picker
                size="mini"
                v-model="bubanAddForm.swatchTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试剂1:" prop="reagent1.key">
              <el-select size="mini" v-model="bubanAddForm.reagent1.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryReagentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="试剂2:">
              <el-select size="mini" v-model="bubanAddForm.reagent2.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryReagentList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="质控品:" prop="qualityControl.key">
              <el-select size="mini" v-model="bubanAddForm.qualityControl.key" placeholder="选择">
                <el-option
                  v-for="(item, index) in queryQualityList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选中位置:">
              <el-input size="mini" disabled v-model="banItem.selectW" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="条形码号:">
              <el-input size="mini" v-model="banItem.barcode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="起始编号:">
              <el-input size="mini" v-model="banItem.startCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="终止编号:">
              <el-input size="mini" v-model="banItem.endCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="选中条码:">
              <el-input size="mini" disabled v-model="banItem.selectCode" placeholder="输入" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <div style="display: flex;justify-content: center;margin:10px 0">
              <el-button type="primary" size="mini" @click="clickSet">设置</el-button>
              <!-- <el-button size="mini">复制</el-button> -->
              <el-button type="primary" size="mini" @click="clickSeave">保存</el-button>
            </div>
          </el-col>

          <!-- 表格 -->
          <el-col :span="10">
            <div id="ban-table-tow">
              <el-table
                v-loading="loading"
                :data="queryRecheckData"
                style="width: 100%;padding:5px;"
                :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
                @row-dblclick="clickRowDB"
              >
                <el-table-column align="center" type="index" width="55" />
                <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
                <el-table-column align="center" prop="bloodProperty.data" label="样本属性" />
                <el-table-column align="center" prop="barCode" label="条形码号" width="150" />
                <el-table-column align="center" prop="bloodNum" label="采血编号" width="150" />
                <el-table-column align="center" prop="bloodReview.data" label="原血复查">
                  <template slot-scope="scope">
                    <span
                      :style="
                        scope.row.bloodReview.data == '是' ? 'color:red' : ''
                      "
                    >{{ scope.row.bloodReview.data }}</span>
                  </template>
                </el-table-column>
              </el-table>
            </div>
            <div id="ban-table-tow">
              <el-table
                v-loading="importLoading"
                :data="queryNormalData"
                style="width: 100%;padding:5px;"
                :header-cell-style="{
                  background: '#333333',
                  color: '#ffffff',
                  textAlign: 'center'
                }"
                @row-dblclick="clickRowDB"
              >
                <el-table-column align="center" type="index" width="55" />
                <el-table-column align="center" prop="expNum" label="实验编号" width="150" />
                <el-table-column align="center" prop="bloodProperty.data" label="样本属性" />
                <el-table-column align="center" prop="barCode" label="条形码号" width="150" />
                <el-table-column align="center" prop="bloodNum" label="采血编号" width="150" />
              </el-table>
            </div>
          </el-col>
          <!-- 布板 -->
          <el-col :span="14">
            <buBan
              v-if="banShow"
              @chanageDataList="chanageDataList"
              @selectRow="selectRow"
              ref="buBanRef"
              :banTotal="banTotal"
              :dataList="banData"
              :codeList="codeList"
              :rowList="columnList"
              :columnList="rowList"
            ></buBan>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import importExcel from "@/api/upload.js";
import DeliveryManageApi from "@/api/DeliveryManage.js";
import { initDicts } from "@/utils/commons";
import QualityManageApi from "@/api/QualityManage.js";
import ConsumableManageApi from "@/api/ConsumableManage.js";
import buBan from "@/components/ban/buBan";

export default {
  components: {
    buBan
  },
  data() {
    return {
      // 转菊花
      loading: false,
      // 点击查看
      seeShow: false,
      // 审核弹窗
      auditShow: false,
      // 原始数据列表弹窗
      ExpListShow: false,
      // 原始数据转菊花
      expLoading: false,
      // 同步数据
      SyncShow: false,
      // 同步按钮不可点击
      butsab: false,
      // 原始数据列表
      expList: [],
      // 原始数据统计
      expItem: {},
      // 查看数据
      seeData: [],
      // 页条数
      pageSize: 10,
      // 页数
      pageIndex: 1,
      // 表格数据
      tableData: [],
      // 选中数据
      selectList: [],
      // 数据上报标题
      title: "",
      // 数据上报数据
      expListData: {
        endExpNum: "",
        experimentCode: {
          data: "",
          key: ""
        },
        experimentDate: "",
        experimentSwatchId: "",
        seq: 1,
        startExpNum: ""
      },
      // 查询数据
      basicData: {
        current: 1,
        map: {},
        model: {
          batchNumber: "",
          experimentCode: {
            data: "",
            key: ""
          },
          flowStatus: {
            data: "",
            key: ""
          },
          qualityControl: "",
          reagent1: "",
          reagent2: "",
          swatchId: {
            key: ""
          },
          swatchMan: "",
          swatchTimeStartEnd: {
            end: "",
            start: ""
          }
        },
        order: "descending",
        size: 10,
        sort: "id"
      },
      // 总数
      total: 0,
      // 字典
      dicts: {
        EXPERIMENT_CODE: {} //实验项目
      },
      // 复检样本
      queryRecheckData: [],
      // 正常样本
      queryNormalData: [],
      // 复检样本转菊花
      queryRechecLoading: false,
      // 正常样本
      queryNormal: [],
      // 正常样本转菊花
      queryNormalLoading: false,
      // 布板弹窗
      bubanShow: false,
      // 正常样本表格转菊花
      importLoading: false,
      // 布板保存数据
      bubanAddForm: {
        batchNumber: "",
        experimentCode: {
          key: ""
        },
        qualityControl: {
          key: ""
        },
        reagent1: {
          key: ""
        },
        reagent2: {
          key: ""
        },
        swatchId: {
          key: ""
        },
        swatchMan: this.$store.state.account.user.name,
        swatchTime:
          new Date().getFullYear().toString() +
          "-" +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          "-" +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString()),
        swatchValue: []
      },
      // 板验证
      bubanAddFormRules: {
        batchNumber: [{ required: true, message: "   ", trigger: "change" }],
        "swatchId.key": [{ required: true, message: "   ", trigger: "change" }],
        swatchMan: [{ required: true, message: "   ", trigger: "change" }],
        swatchTime: [{ required: true, message: "   ", trigger: "change" }],
        "reagent1.key": [{ required: true, message: "   ", trigger: "change" }],
        "qualityControl.key": [
          { required: true, message: "   ", trigger: "change" }
        ]
      },
      // 板本地操作数据
      banItem: {
        selectW: "",
        barcode: "",
        startCode: "",
        endCode: "",
        selectCode: ""
      },
      // 布板方案
      swatchList: [],
      // 试剂
      queryReagentList: [],
      // 质控品
      queryQualityList: [],
      // 布板数据
      banData: [],
      // 板数量
      banTotal: 0,
      // 显示布板
      banShow: false,
      // 当前点击行
      clickRow: [],
      // 选中的编码
      codeList: [],
      // 布板列数
      rowList: [],
      // 布板行数
      columnList: []
    };
  },
  mounted() {
    initDicts(["EXPERIMENT_CODE"], this.dicts);
    this.getList(this.basicData);
  },
  methods: {
    // 点击同步
    clickSync() {
      if (this.expListData.experimentCode.key == "") {
        this.$message.error("请选择项目");
        return;
      }
      if (this.expListData.experimentDate == "") {
        this.$message.error("请选择日期");
        return;
      }
      let data = {
        code: this.expListData.experimentCode.key,
        date: this.expListData.experimentDate
      };
      this.butsab = true;
      DeliveryManageApi.experimentData.sync(data).then(res => {
        if (res.status == 200) {
          setTimeout(() => {
            this.$message({
              message: res.statusText,
              type: "success"
            });
            this.butsab = false;
          }, 2000);
        } else {
          this.$message.error(res.statusText);
        }
      });
    },
    // 上报数据
    clickUpdateData() {
      // let data = [];
      // this.expList.forEach((item, index) => {
      //   data[index] = {
      //     expNum: Number(item.expNum),
      //     experimentCode: {
      //       data: "",
      //       key: this.expListData.experimentCode.key
      //     },
      //     experimentDate: item.experimentDate,
      //     id: item.id,
      //     sampleId: item.sampleId,
      //     seq: item.seq,
      //     uid: item.uid
      //   };
      // });
      if (this.expList.length == 0) {
        this.$message.error("请先查询！");
        return;
      }
      DeliveryManageApi.experimentData
        .saveExperimentData(this.expList)
        .then(res => {
          if (res.status == 200) {
            this.$message({
              message: res.statusText,
              type: "success"
            });
          } else {
            this.$message.error(res.statusText);
          }
        });
    },
    // 原始数据查询
    clickExpQuery() {
      this.expLoading = true;
      DeliveryManageApi.experimentData
        .queryExperimentData(this.expListData)
        .then(res => {
          this.expList = res.data.data;
        })
        .finally(() => {
          this.expLoading = false;
        });
      DeliveryManageApi.experimentData
        .queryExperimentDataSummary(this.expListData)
        .then(res => {
          this.expItem = res.data.data;
        });
    },
    // 获取数据
    getList(data) {
      this.loading = true;
      DeliveryManageApi.experimentData
        .page(data)
        .then(res => {
          if (res.status === 200) {
            this.tableData = res.data.data.records;
          } else {
            this.$message.error(res.statusText);
          }
        })
        .finally(() => (this.loading = false));
    },
    // 选中数据操作
    selectChanage(v) {
      this.selectList = v;
    },
    // 布板#################################
    // 保存
    clickSeave() {
      this.$refs["basicForm"].validate(valid => {
        if (valid) {
          DeliveryManageApi.addSample.putData(this.bubanAddForm).then(res => {
            if (res.status === 200) {
              this.$message({
                type: "success",
                message: res.statusText
              });
              this.bubanShow = false;
              this.resultData();
            } else {
              this.$message.error(res.statusText);
            }
          });
        } else {
          return false;
        }
      });
    },
    // 点击布板
    clickDbRow(data) {
      this.resultData();
      this.bubanShow = true;
      this.bubanAddForm.batchNumber = data.batchNumber;
      this.bubanAddForm.swatchId = data.swatchId;
      this.bubanAddForm.experimentCode = data.experimentCode;
      this.bubanAddForm.swatchMan = data.swatchMan;
      this.bubanAddForm.reagent1 = data.reagent1;
      this.bubanAddForm.reagent2 = data.reagent2;
      this.bubanAddForm.qualityControl = data.qualityControl;
      // 查询已存复检
      DeliveryManageApi.experimentData
        .querySavedRecheck({
          experimentSwatchId: data.id
        })
        .then(res => {
          this.queryRecheckData = res.data.data;
        });
      // 查询已存初验
      DeliveryManageApi.experimentData
        .querySavedNormal({
          experimentSwatchId: data.id
        })
        .then(res => {
          this.queryNormalData = res.data.data;
        });
      // 查询已存布板
      DeliveryManageApi.experimentData
        .querySavedSwatch({
          experimentSwatchId: data.id
        })
        .then(res => {
          this.bubanAddForm = res.data.data;
          console.log(res.data.data);

          this.banData = res.data.data.swatchValue;
          this.banTotal = 0;
          res.data.data.swatchValue.forEach(item => {
            if (item.ban > this.banTotal) {
              this.banTotal++;
            }
          });
          this.columnList = [];
          this.rowList = [];
          this.filRowList(res.data.data.swatchValue).forEach((item, index) => {
            this.rowList[index] = {
              id: item,
              type: ""
            };
          });
          if (this.rowList[0].type != "banIndex") {
            this.rowList.unshift({ id: "1", type: "banIndex" });
          }
          this.columnList = this.filColumnList(res.data.data.swatchValue); //根据布板数组过滤行数
          this.banShow = true;
          // 重置布板数据
          setTimeout(() => {
            this.$refs.buBanRef.getList();
          }, 200);

          // 方案名称
          let swatchSchemeManage = {
            current: 1,
            map: {},
            model: {
              experimentCode: {
                data: "",
                key: this.bubanAddForm.experimentCode.key
              },
              swatchName: ""
            },
            order: "descending",
            size: 10,
            sort: "id"
          };
          QualityManageApi.swatchSchemeManage
            .page(swatchSchemeManage)
            .then(res => {
              this.swatchList = res.data.data.records;
            });

          // 试剂名称
          ConsumableManageApi.reagentManage
            .queryReagent({ code: this.bubanAddForm.experimentCode.key })
            .then(res => {
              this.queryReagentList = res.data.data;
            });
          // 质控品
          ConsumableManageApi.reagentManage
            .queryQuality({ code: this.bubanAddForm.experimentCode.key })
            .then(res => {
              this.queryQualityList = res.data.data;
            });
        });
    },
    // 重置数据
    resultData() {
      this.banShow = false;
      this.bubanAddForm = {
        batchNumber: "",
        experimentCode: {
          key: ""
        },
        qualityControl: {
          key: ""
        },
        reagent1: {
          key: ""
        },
        reagent2: {
          key: ""
        },
        swatchId: {
          key: ""
        },
        swatchMan: this.$store.state.account.user.name,
        swatchTime:
          new Date().getFullYear().toString() +
          "-" +
          ((new Date().getMonth() + 1).toString() < 10
            ? "0" + (new Date().getMonth() + 1).toString()
            : (new Date().getMonth() + 1).toString()) +
          "-" +
          (new Date().getDate().toString() < 10
            ? "0" + new Date().getDate().toString()
            : new Date().getDate().toString()),
        swatchValue: []
      };
      this.banItem = {
        selectW: "",
        barcode: "",
        startCode: "",
        endCode: "",
        selectCode: ""
      };
    },
    // 点击设置
    clickSet() {
      if (this.bubanAddForm.swatchId.key == "") {
        this.$message.error("请选择布板方案");
      } else if (this.banItem.selectW == "") {
        this.$message.error("请选择起始位置");
      } else if (
        (this.banItem.startCode != "" && this.banItem.endCode == "") ||
        (this.banItem.startCode == "" && this.banItem.endCode != "")
      ) {
        this.$message.error("编号无数字部分");
      } else if (this.banItem.startCode > this.banItem.endCode) {
        this.$message.error("起始编号不能大于终止编号");
      } else if (this.banItem.endCode - this.banItem.startCode > 2000) {
        this.$message.error("编号区间跨度过大");
      } else if (this.banItem.startCode != "" && this.banItem.endCode != "") {
        this.codeList = [];
        let codeList = [];
        if (
          isNaN(Number(this.banItem.startCode)) ||
          isNaN(Number(this.banItem.endCode))
        ) {
          this.$message.error("填充的实验编号不能存在英文或者特殊符号");
          return;
        }
        for (
          let index = this.banItem.startCode;
          index < Number(this.banItem.endCode) + 1;
          index++
        ) {
          codeList.push(index);
        }
        this.codeList = codeList;
        if (this.codeList.length > 0) {
          setTimeout(() => {
            this.$refs.buBanRef.setCode();
          }, 300);
        }
      } else {
        let list = this.banData;
        let arr = list.map(item => item.s);
        this.codeList = [];
        this.queryNormalData.forEach((item, index) => {
          if (arr.indexOf(item.expNum) > -1) {
          } else {
            this.codeList.push(item.expNum);
          }
        });
        if (this.codeList.length > 0) {
          setTimeout(() => {
            this.$refs.buBanRef.setCode();
          }, 300);
        }
      }
    },
    // 点击当前行设置布板内部数据
    clickRowDB(v) {
      let list = this.banData;
      let arr = list.map(item => item.s);
      this.codeList = [];
      if (arr.indexOf(v.expNum) > -1) {
        this.$message.error("此条形码号样本已经布板");
      } else {
        this.codeList.push(v.expNum);
      }
      if (this.codeList.length > 0) {
        setTimeout(() => {
          this.$refs.buBanRef.setCode();
        }, 300);
      }
    },
    // 获取当前点击行
    selectRow(v) {
      this.clickRow = v;
      this.banItem.selectW = v.pos;
    },
    // 布板内数据变化
    chanageDataList(v) {
      var dataList = this.queryRecheckData.concat(this.queryNormalData);
      var codeList = [];
      dataList.forEach(item => {
        codeList.push(item.expNum);
      });
      v.forEach((item, index) => {
        codeList.forEach(i => {
          if (item.s == i) {
            item.exist = "Y";
          }
        });
      });
      this.bubanAddForm.swatchValue = v;
    },
    // 选择布板方案
    swatchIdChanage(v) {
      QualityManageApi.swatchSchemeManage
        .getById(this.bubanAddForm.swatchId.key)
        .then(res => {
          this.banData = res.data.data.swatchModel;
          this.banTotal = res.data.data.swatchNum;
          this.columnList = [];
          this.rowList = [];
          this.filRowList(res.data.data.swatchModel).forEach((item, index) => {
            this.rowList[index] = {
              id: item,
              type: ""
            };
          });
          if (this.rowList[0].type != "banIndex") {
            this.rowList.unshift({ id: "1", type: "banIndex" });
          }
          // this.rowList = this.filRowList(res.data.data.swatchModel); //根据布板数组过滤列数
          this.columnList = this.filColumnList(res.data.data.swatchModel); //根据布板数组过滤行数

          this.banShow = true;
          // 重置布板数据
          setTimeout(() => {
            this.$refs.buBanRef.getList();
          }, 200);
        });
    },
    // 过滤去重(获取布板列数)
    filRowList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(item.r);
      });
      return Array.from(new Set(data));
    },
    // 过滤去重(获取布板列数)
    filColumnList(arr) {
      let data = [];
      arr.forEach(item => {
        data.push(
          this.direction.key == "horizontal" ? item.r : item.pos.split("-")[1]
        );
      });
      return Array.from(new Set(data));
    },
    // 布板结束##################################
    // 删除数据
    clickDelete() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要删除的数据");
        return;
      }
      // 加删除验证
      this.$confirm(`是否删除${this.selectList.length}条数据?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.selectList.forEach(item => {
          DeliveryManageApi.experimentData
            .delete({
              "ids[]": item.id
            })
            .then(res => {
              this.getList(this.basicData);
            });
        });
      });
    },
    // 点击审核
    clickAudit() {
      this.auditShow = true;
    },
    clickShenhe() {
      if (this.selectList.length == 0) {
        this.$message.error("请选择要提交审核的数据");
        return;
      }
      if (this.selectList.length > 1) {
        this.$message.error("之鞥选择一条要提交审核的数据");
        return;
      }
      DeliveryManageApi.experimentData
        .submitAudit(this.selectList[0].id)
        .then(res => {
          if (res.status == 200) {
            setTimeout(() => {
              this.$message({
                message: res.statusText,
                type: "success"
              });
              this.getList(this.basicData);
            }, 2000);
          } else {
            this.$message.error(res.statusText);
          }
        });
    },
    // 审核选择项目
    selectExperimentCode(v) {
      this.title = v.data + "原始数据";
      this.expListData.experimentCode = v;
      if (v.key == "THA") {
        this.ExpListShow = true;
      }
      this.auditShow = false;
      this.basicData.model.experimentCode = {
        data: "",
        key: ""
      };
    },
    // 点击分页
    handleSizeChange: function(val) {
      this.basicData.size = val;
      this.getList(this.basicData);
    },
    // 选择页码
    handleCurrentChange: function(currentPage) {
      this.basicData.current = currentPage;
      this.getList(this.basicData);
    }
  }
};
</script>
<style lang="less">
#experimentData {
}

#experimentData-dialog {
  display: flex;
  justify-content: center;
  align-items: center;
  .el-dialog {
    margin-top: 0 !important;
  }
  .el-message-box__message {
    width: 280px;
    overflow: hidden;
    white-space: normal;
    word-break: break-all;
  }
  #ban-table-tow {
    .el-table__body-wrapper {
      height: 200px !important;
      overflow-y: auto;
    }
  }
  .el-dialog__title {
    color: #fff;
  }
  .el-form-item__content {
    width: 80%;
    .el-select {
      width: 100%;
    }
    .el-date-editor {
      width: 100%;
    }
  }
}
</style>